package org.vergil.core.thread.producerconsumer;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created by vergil on 17-3-18.
 */
public class Business {
    private BlockingQueue<String> queue = new LinkedBlockingDeque<>(100);
    private int count;

    public void push(int count, String product) throws InterruptedException {
        for (int i = 0; i <= count; i++) {
            queue.put(product);
        }
        System.out.println("set after queue size is " + queue.size());
    }

    public String getProduct() throws InterruptedException {
        return queue.take();
    }

    public List<String> getProducts(int num) throws InterruptedException {
        List<String> products = new ArrayList<>();
        for (int i = 0; i <= num; i++) {
            products.add(getProduct());
        }
        System.out.println("get after queue size is " + queue.size());
        return products;
    }

    public BlockingQueue<String> getQueue() {
        return queue;
    }
}
